package com.objectproject.main.model;

import java.util.ArrayList;

import org.springframework.web.multipart.MultipartFile;

import com.objectproject.main.enumeration.ValueType;
import com.objectproject.main.exception.PropertyRefineException;

public class MyPropertiesCommandModel {
	
	protected int propertySize;
	protected ArrayList<Long> propertyIds;
	protected ArrayList<Long> propertyModificationAuthIds;
	protected ArrayList<String> isNexts;
	protected ArrayList<String> isHiddens;
	protected ArrayList<String> isStatics;
	protected ArrayList<String> isSystemProperties;
	protected ArrayList<ValueType> valueTypes;
	protected ArrayList<Long> myObjectQualifiers;
	protected ArrayList<String> viewMinis;
	protected ArrayList<String> viewSimples;
	protected ArrayList<String> viewCards;
	protected ArrayList<String> viewNormals;
	protected ArrayList<Integer> dedicatedLocaleIds;
	protected ArrayList<String> labels;
	protected ArrayList<Long> valueIds;

	protected ArrayList<String> helpTexts;
	
	
	
	public MyPropertiesCommandModel() {
		super();
		this.propertyIds =  new ArrayList<Long>();
		this.propertyModificationAuthIds = new ArrayList<Long>();
		this.isNexts = new ArrayList<String>();
		this.isHiddens = new ArrayList<String>();
		this.isStatics = new ArrayList<String>();
		this.isSystemProperties = new ArrayList<String>();
		this.valueTypes = new ArrayList<ValueType>();
		this.myObjectQualifiers = new ArrayList<Long>();
		this.viewMinis = new ArrayList<String>();
		this.viewSimples = new ArrayList<String>();
		this.viewCards = new ArrayList<String>();
		this.viewNormals = new ArrayList<String>();
		
		this.labels = new ArrayList<String>();
		
		//오브젝트 표시 전용
		this.valueIds = new ArrayList<Long>();
		
		this.helpTexts = new ArrayList<String>();
		
	}
	
	//널 값이나 스트링 리스트를 적절하게 변경
	//길이 정도만 유효성 체크하고 null 값 처리등은 뒤에 맞긴다.
	public void refine() throws PropertyRefineException{
		
		
		
		if(propertyIds.size() != propertySize + 1)
			throw new PropertyRefineException("propertyIds의 길이가 " + propertySize + "가 아님");
		if(propertyModificationAuthIds.size() != propertySize + 1)
			throw new PropertyRefineException("propertyModificationAuthIds 길이가 " + propertySize + "가 아님");
		if(isNexts.size() != propertySize + 1)
			throw new PropertyRefineException("isNexts 길이가 " + propertySize + "가 아님");
		if(isHiddens.size() != propertySize + 1)
			throw new PropertyRefineException("isHiddens 길이가 " + propertySize + "가 아님");
		if(isStatics.size() != propertySize + 1)
			throw new PropertyRefineException("isStatics 길이가 " + propertySize + "가 아님");
		if(isSystemProperties.size() != propertySize + 1)
			throw new PropertyRefineException("isSystemProperties 길이가 " + propertySize + "가 아님");
		if(valueTypes.size() != propertySize + 1)
			throw new PropertyRefineException("valueTypes 길이가 " + propertySize + "가 아님");
		if(myObjectQualifiers.size() != propertySize + 1)
			throw new PropertyRefineException("myObjectQualifiers 길이가 " + propertySize + "가 아님");
		if(viewMinis.size() != propertySize + 1)
			throw new PropertyRefineException("viewMinis 길이가 " + propertySize + "가 아님");
		if(viewSimples.size() != propertySize + 1)
			throw new PropertyRefineException("viewSimples 길이가 " + propertySize + "가 아님");
		if(viewCards.size() != propertySize + 1)
			throw new PropertyRefineException("viewCards 길이가 " + propertySize + "가 아님");
		if(viewNormals.size() != propertySize + 1)
			throw new PropertyRefineException("viewNormals 길이가 " + propertySize + "가 아님");
		if(labels.size() != propertySize + 1)
			throw new PropertyRefineException("labels 길이가 " + propertySize + "가 아님");
		if(valueIds.size() != propertySize + 1)
			throw new PropertyRefineException("valueIds 길이가 " + propertySize + "가 아님");
		if(helpTexts.size() != propertySize + 1)
			throw new PropertyRefineException("helpTexts 길이가 " + propertySize + "가 아님");
		
		//참고 : 0번째 프로퍼티는 더미 프로퍼티, 파라미터 바인딩시 배열처리가 스프링에서 불안정해 어쩔수없음
		for(int i = 1 ; i < propertySize + 1 ; i++){
			
			if(propertyIds.get(i) == null){
				propertyIds.set(i, new Long("0"));
			}
			
			if(propertyModificationAuthIds.get(i) == null){
				propertyModificationAuthIds.set(i, new Long("0"));
			}
			
			isNexts.set(i, refineBooleanString(isNexts.get(i)));
			isHiddens.set(i, refineBooleanString(isHiddens.get(i)));
			isStatics.set(i, refineBooleanString(isStatics.get(i)));
			isSystemProperties.set(i, refineBooleanString(isSystemProperties.get(i)));
			
			if(valueTypes.get(i) == null){
				throw new PropertyRefineException("valueTypes 프로퍼티의 " + i + "번째 값 타입이 NULL로 판명됨");
			}
			
			
			if(myObjectQualifiers.get(i) == null){
				myObjectQualifiers.set(i, new Long("0"));
			}
			
			viewMinis.set(i, refineBooleanString(viewMinis.get(i)));
			viewSimples.set(i, refineBooleanString(viewSimples.get(i)));
			viewCards.set(i, refineBooleanString(viewCards.get(i)));
			viewNormals.set(i, refineBooleanString(viewNormals.get(i)));
			
			if((labels.get(i)).trim().equals("")){
				labels.set(i, null);
			}
			
			if(valueIds.get(i) == null){
				valueIds.set(i, new Long("0"));
			}
			
			if((helpTexts.get(i)).trim().equals("")){
				helpTexts.set(i, null);
			}
			
		}
		
	}
	
	private String refineBooleanString(String booleanString){
		
		String trueString = "true";
		String falseString = "false";
		
		if(booleanString != null){
			return trueString;
		}else{
			return falseString;
		}
	}



	public int getPropertySize() {
		return propertySize;
	}



	public void setPropertySize(int propertySize) {
		this.propertySize = propertySize;
	}



	public ArrayList<Long> getPropertyIds() {
		return propertyIds;
	}



	public void setPropertyIds(ArrayList<Long> propertyIds) {
		this.propertyIds = propertyIds;
	}



	public ArrayList<Long> getPropertyModificationAuthIds() {
		return propertyModificationAuthIds;
	}



	public void setPropertyModificationAuthIds(
			ArrayList<Long> propertyModificationAuthIds) {
		this.propertyModificationAuthIds = propertyModificationAuthIds;
	}



	public ArrayList<String> getIsNexts() {
		return isNexts;
	}



	public void setIsNexts(ArrayList<String> isNexts) {
		this.isNexts = isNexts;
	}



	public ArrayList<String> getIsHiddens() {
		return isHiddens;
	}



	public void setIsHiddens(ArrayList<String> isHiddens) {
		this.isHiddens = isHiddens;
	}



	public ArrayList<String> getIsStatics() {
		return isStatics;
	}



	public void setIsStatics(ArrayList<String> isStatics) {
		this.isStatics = isStatics;
	}

	public ArrayList<String> getIsSystemProperties() {
		return isSystemProperties;
	}

	public void setIsSystemProperties(ArrayList<String> isSystemProperties) {
		this.isSystemProperties = isSystemProperties;
	}

	public ArrayList<ValueType> getValueTypes() {
		return valueTypes;
	}

	public void setValueTypes(ArrayList<ValueType> valueTypes) {
		this.valueTypes = valueTypes;
	}

	public ArrayList<Long> getMyObjectQualifiers() {
		return myObjectQualifiers;
	}

	public void setMyObjectQualifiers(ArrayList<Long> myObjectQualifiers) {
		this.myObjectQualifiers = myObjectQualifiers;
	}

	public ArrayList<String> getViewMinis() {
		return viewMinis;
	}

	public void setViewMinis(ArrayList<String> viewMinis) {
		this.viewMinis = viewMinis;
	}

	public ArrayList<String> getViewSimples() {
		return viewSimples;
	}

	public void setViewSimples(ArrayList<String> viewSimples) {
		this.viewSimples = viewSimples;
	}

	public ArrayList<String> getViewCards() {
		return viewCards;
	}

	public void setViewCards(ArrayList<String> viewCards) {
		this.viewCards = viewCards;
	}

	public ArrayList<String> getViewNormals() {
		return viewNormals;
	}

	public void setViewNormals(ArrayList<String> viewNormals) {
		this.viewNormals = viewNormals;
	}

	public ArrayList<Integer> getDedicatedLocaleIds() {
		return dedicatedLocaleIds;
	}

	public void setDedicatedLocaleIds(ArrayList<Integer> dedicatedLocaleIds) {
		this.dedicatedLocaleIds = dedicatedLocaleIds;
	}

	public ArrayList<String> getLabels() {
		return labels;
	}

	public void setLabels(ArrayList<String> labels) {
		this.labels = labels;
	}

	public ArrayList<Long> getValueIds() {
		return valueIds;
	}

	public void setValueIds(ArrayList<Long> valueIds) {
		this.valueIds = valueIds;
	}

	public ArrayList<String> getHelpTexts() {
		return helpTexts;
	}

	public void setHelpTexts(ArrayList<String> helpTexts) {
		this.helpTexts = helpTexts;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("propertySize : " + this.propertySize + "\n");
		
		for(int i = 1 ; i < this.propertySize+1 ; i++){
			
			sb.append("propertyIds : " + this.propertyIds.get(i) + "\n");
			sb.append("propertyModificationAuthIds : " + this.propertyModificationAuthIds.get(i) + "\n");
			sb.append("isNexts : " + this.isNexts.get(i) + "\n");
			sb.append("isHiddens : " + this.isHiddens.get(i) + "\n");
			sb.append("isStatics : " + this.isStatics.get(i) + "\n");
			sb.append("isSystemProperties : " + this.isSystemProperties.get(i) + "\n");
			sb.append("valueTypes : " + this.valueTypes.get(i) + "\n");
			sb.append("myObjectQualifiers : " + this.myObjectQualifiers.get(i) + "\n");
			sb.append("viewMinis : " + this.viewMinis.get(i) + "\n");
			sb.append("viewSimples : " + this.viewSimples.get(i) + "\n");
			sb.append("viewCards : " + this.viewCards.get(i) + "\n");
			sb.append("viewNormals : " + this.viewNormals.get(i) + "\n");
			sb.append("labels : " + this.labels.get(i) + "\n");
			sb.append("valueIds : " + this.valueIds.get(i) + "\n");
			/*sb.append("primitiveStrings : " + this.primitiveStrings.get(i) + "\n");*/
			/*sb.append("primitiveFiles : " + this.primitiveFiles.get(i) + "\n");*/
			sb.append("helpTexts : " + this.helpTexts.get(i) + "\n\n");
			
		}
		return sb.toString();
	}

}
